package com.oscar.ehome.view.setview;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.oscar.ehome.R;
import com.oscar.ehome.base.activity.BasesActivity;
import com.oscar.ehome.bean.setbean.SetMessageBean;
import com.oscar.ehome.presenter.BasePresenter;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.ToastUtil;
import com.oscar.ehome.utils.view.progressview.ProgressFrameLayout;
import com.oscar.ehome.view.messageview.MessageDetilActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/7/21
 * 评级列表
 */

public class RateListActivity extends BasesActivity {

    /**
     * 返回
     */
    @BindView(R.id.title_img_back)
    ImageView titleImgBack;

    @BindView(R.id.ratelist_moren)
    ProgressFrameLayout ratelist_moren;
    /**
     * 返回
     */
    @BindView(R.id.title_layout_left)
    RelativeLayout titleLayoutLeft;
    /**
     * 标题
     */
    @BindView(R.id.title_topbar)
    TextView titleTopbar;
    /**
     *
     */
    @BindView(R.id.xing1)
    ImageView xing1;
    /**
     *
     */
    @BindView(R.id.xing2)
    ImageView xing2;
    /**
     *
     */
    @BindView(R.id.xing3)
    ImageView xing3;
    /**
     * 增员人数
     */
    @BindView(R.id.addmember_size)
    TextView addmemberSize;
    /**
     * 签到次数
     */

    @BindView(R.id.shuju)
    LinearLayout shuju;
    @BindView(R.id.sgin_size)
    TextView sginSize;
    /**
     * 参与活动次数
     */
    @BindView(R.id.addactivity_size)
    TextView addactivitySize;
    /**
     * 学习时间
     */
    @BindView(R.id.learn_size)
    TextView learnSize;
    /**
     * 一星说明
     */
    @BindView(R.id.oneleve_message)
    TextView oneleveMessage;
    /**
     * 二星说明
     */
    @BindView(R.id.twoleve_message)
    TextView twoleveMessage;
    /**
     * 三星说明
     */
    @BindView(R.id.threeleve_message)
    TextView threeleveMessage;
    /**
     * title布局
     */
    @BindView(R.id.basetitle_bar)
    RelativeLayout basetitleBar;

    String token = "";
    SetMessageBean setMessageBean;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ratelist);
        ButterKnife.bind(this);
        basetitleBar.setBackgroundColor(Color.parseColor(SystemConfigFactory.getInstance(RateListActivity.this).getSystemConfig().getColor()));
        initView();
        initData();
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    /**
     * 初始化数据
     */
    public void initView() {
        titleImgBack.setImageResource(R.mipmap.fanhui);
        titleImgBack.setVisibility(View.VISIBLE);
        titleTopbar.setText("评级列表");
        token = SystemConfigFactory.getInstance(RateListActivity.this).getSystemConfig().getToken();

        String message = getIntent().getStringExtra("message");
        if (message != null && !"".equals(message)) {
            setMessageBean = new Gson().fromJson(message, SetMessageBean.class);
        }
    }


    /**
     * 请求数据
     */
    public void initData() {
        Log.e("shuju", "initData: "+setMessageBean.getStarLevel());
        if (setMessageBean != null) {
            if (setMessageBean.getStarLevel() != null&&!setMessageBean.getStarLevel().equals("-1") ){
                ratelist_moren.stopRefresh();
                shuju.setVisibility(View.VISIBLE);
                Log.e("shujuss", "initData: "+setMessageBean.getStarLevel());
                switch (setMessageBean.getStarLevel()) {
                    case "0":
                        xing1.setImageResource(R.mipmap.xinghui);
                        xing2.setImageResource(R.mipmap.xinghui);
                        xing3.setImageResource(R.mipmap.xinghui);
                        break;
                    case "1":
                        xing1.setImageResource(R.mipmap.xing);
                        xing2.setImageResource(R.mipmap.xinghui);
                        xing3.setImageResource(R.mipmap.xinghui);
                        break;
                    case "2":
                        xing1.setImageResource(R.mipmap.xing);
                        xing2.setImageResource(R.mipmap.xing);
                        xing3.setImageResource(R.mipmap.xinghui);
                        break;
                    case "3":
                        xing1.setImageResource(R.mipmap.xing);
                        xing2.setImageResource(R.mipmap.xing);
                        xing3.setImageResource(R.mipmap.xing);
                        break;
                }
            }else{
                shuju.setVisibility(View.GONE);
                ratelist_moren.setNoResult();
                ToastUtil.show(RateListActivity.this,"未完" +
                        "善评级规则，请联系管理员");
            }
            if (setMessageBean.getAddUserNum() == null) {
                addmemberSize.setText("0人");
            } else {
                addmemberSize.setText(setMessageBean.getAddUserNum() + "人");
            }
            if (setMessageBean.getCheckworkNum() == null) {
                sginSize.setText("0次");
            } else {
                sginSize.setText(setMessageBean.getCheckworkNum() + "次");
            }
            if (setMessageBean.getEventNum() == null) {
                addactivitySize.setText("0次");
            } else {
                addactivitySize.setText(setMessageBean.getEventNum() + "次");
            }
            if (setMessageBean.getLearnTime() == null) {
                learnSize.setText("0分钟");
            } else {
                learnSize.setText(setMessageBean.getLearnTime() + "分钟");
            }
            String year = "";
            if (setMessageBean.getStarRules() != null) {
                if (setMessageBean.getStarRules().getCycleId() != null) {
                    switch (setMessageBean.getStarRules().getCycleId()) {
                        case "1"://周
                            year = "周";
                            break;
                        case "2"://月
                            year = "月";
                            break;
                        case "3"://季度
                            year = "季度";
                            break;
                        case "4"://年
                            year = "年";
                            break;
                    }
                    oneleveMessage.setText("每" + year + "增员" + setMessageBean.getStarRules().getOneAdduserNum() + "人，" +
                            "考勤签到" + setMessageBean.getStarRules().getOneCheckworkNum() + "次，" +
                            "参与活动" + setMessageBean.getStarRules().getOneEventNum() + "次，" +
                            "学习" + setMessageBean.getStarRules().getOneLearnMinutes() + "分钟即可获得；");
                    twoleveMessage.setText("每" + year + "增员" + setMessageBean.getStarRules().getTwoAdduserNum() + "人，" +
                            "考勤签到" + setMessageBean.getStarRules().getTwoCheckworkNum() + "次，" +
                            "参与活动" + setMessageBean.getStarRules().getTwoEventNum() + "次，" +
                            "学习" + setMessageBean.getStarRules().getTwoLearnMinutes() + "分钟即可获得；");
                    threeleveMessage.setText("每" + year + "增员" + setMessageBean.getStarRules().getThreeAdduserNum() + "人，" +
                            "考勤签到" + setMessageBean.getStarRules().getThreeCheckworkNum() + "次，" +
                            "参与活动" + setMessageBean.getStarRules().getThreeEventNum() + "次，" +
                            "学习" + setMessageBean.getStarRules().getThreeLearnMinutes() + "分钟即可获得；");
                }
            }
        } else {
            xing1.setImageResource(R.mipmap.xinghui);
            xing2.setImageResource(R.mipmap.xinghui);
            xing3.setImageResource(R.mipmap.xinghui);
            addmemberSize.setText("0人");
            sginSize.setText("0次");
            addactivitySize.setText("0次");
            learnSize.setText("0分钟");
        }
    }

    @OnClick(R.id.title_layout_left)
    public void onViewClicked() {
        finish();
    }


}
